#CODE FOR GENERATING FIGURE 2

#############
#Leadership

library(foreign)
library(lattice)
library(extrafont)
library(readstata13)
library(scales)
#library(sm)
loadfonts()
datadem<-read.dta13("MarginalMatrix_Dem_95ci_DYDX.dta")
datarep<-read.dta13("MarginalMatrix_Rep_95ci_DYDX.dta")
datademmean<-read.dta13("MarginalMatrix_Dem_Means_DYDX.dta")
datarepmean<-read.dta13("MarginalMatrix_Rep_Means_DYDX.dta")

Scale<-datadem[,1]
DemLeaderLB<-datadem[,2]
DemLeaderUB<-datadem[,3]
DemCompetentLB<-datadem[,4]
DemCompetentUB<-datadem[,5]
DemFTLB<-datadem[,6]
DemFTUB<-datadem[,7]
DemJobLB<-datadem[,8]
DemJobUB<-datadem[,9]
DemRightLB<-datadem[,10]
DemRightUB<-datadem[,11]
DemEffectiveLB<-datadem[,12]
DemEffectiveUB<-datadem[,13]

RepLeaderLB<-datarep[,2]
RepLeaderUB<-datarep[,3]
RepCompetentLB<-datarep[,4]
RepCompetentUB<-datarep[,5]
RepFTLB<-datarep[,6]
RepFTUB<-datarep[,7]
RepJobLB<-datarep[,8]
RepJobUB<-datarep[,9]
RepRightLB<-datarep[,10]
RepRightUB<-datarep[,11]
RepEffectiveLB<-datarep[,12]
RepEffectiveUB<-datarep[,13]

DemLeaderMeans<-datademmean[,2]
DemCompetentMeans<-datademmean[,3]
DemFTMeans<-datademmean[,4]
DemJobMeans<-datademmean[,5]
DemRightMeans<-datademmean[,6]
DemEffectiveMeans<-datademmean[,7]

RepLeaderMeans<-datarepmean[,2]
RepCompetentMeans<-datarepmean[,3]
RepFTMeans<-datarepmean[,4]
RepJobMeans<-datarepmean[,5]
RepRightMeans<-datarepmean[,6]
RepEffectiveMeans<-datarepmean[,7]

pdf(file="Figure2a.pdf", family="Bookman")
plot(0, 1, type="n", xlim=c(0,1), ylim=c(-.15, .15), xlab="Moderator: Perceived Obstructiveness", ylab="Marginal Effect of Gender on Perceived Leadership")
title(main="Perceived Leadership Abilities")
box() 

polygon(c(Scale, rev(Scale)), c(DemLeaderLB, rev(DemLeaderUB)), col="gray72", border=NA)

points(Scale, DemLeaderMeans, type="l")

polygon(c(Scale, rev(Scale)), c(RepLeaderLB, rev(RepLeaderUB)), density=20, angle=45, col="black")

points(Scale, RepLeaderMeans, type="l")

abline(0, 0, col="black", lty=2, lwd=2)

legend("bottomright", cex=.98, legend=c('Democrats', 'Republicans'), fill=c("gray72", "black"), density=c(NA, 30), angle=c(NA, 45), border=c(NA, "black"))

dev.off()


#############
#Competence

library(foreign)
library(lattice)
library(extrafont)
library(readstata13)
library(scales)
#library(sm)
loadfonts()
datadem<-read.dta13("MarginalMatrix_Dem_95ci_DYDX.dta")
datarep<-read.dta13("MarginalMatrix_Rep_95ci_DYDX.dta")
datademmean<-read.dta13("MarginalMatrix_Dem_Means_DYDX.dta")
datarepmean<-read.dta13("MarginalMatrix_Rep_Means_DYDX.dta")

Scale<-datadem[,1]
DemLeaderLB<-datadem[,2]
DemLeaderUB<-datadem[,3]
DemCompetentLB<-datadem[,4]
DemCompetentUB<-datadem[,5]
DemFTLB<-datadem[,6]
DemFTUB<-datadem[,7]
DemJobLB<-datadem[,8]
DemJobUB<-datadem[,9]
DemRightLB<-datadem[,10]
DemRightUB<-datadem[,11]
DemEffectiveLB<-datadem[,12]
DemEffectiveUB<-datadem[,13]

RepLeaderLB<-datarep[,2]
RepLeaderUB<-datarep[,3]
RepCompetentLB<-datarep[,4]
RepCompetentUB<-datarep[,5]
RepFTLB<-datarep[,6]
RepFTUB<-datarep[,7]
RepJobLB<-datarep[,8]
RepJobUB<-datarep[,9]
RepRightLB<-datarep[,10]
RepRightUB<-datarep[,11]
RepEffectiveLB<-datarep[,12]
RepEffectiveUB<-datarep[,13]

DemLeaderMeans<-datademmean[,2]
DemCompetentMeans<-datademmean[,3]
DemFTMeans<-datademmean[,4]
DemJobMeans<-datademmean[,5]
DemRightMeans<-datademmean[,6]
DemEffectiveMeans<-datademmean[,7]

RepLeaderMeans<-datarepmean[,2]
RepCompetentMeans<-datarepmean[,3]
RepFTMeans<-datarepmean[,4]
RepJobMeans<-datarepmean[,5]
RepRightMeans<-datarepmean[,6]
RepEffectiveMeans<-datarepmean[,7]

pdf(file="Figure2b.pdf", family="Bookman")
plot(0, 1, type="n", xlim=c(0,1), ylim=c(-.15, .15), xlab="Moderator: Perceived Obstructiveness", ylab="Marginal Effect of Gender on Perceived Competence")
title(main="Perceived Competence")
box() 

polygon(c(Scale, rev(Scale)), c(DemCompetentLB, rev(DemCompetentUB)), col="gray72", border=NA)

points(Scale, DemCompetentMeans, type="l")

polygon(c(Scale, rev(Scale)), c(RepCompetentLB, rev(RepCompetentUB)), density=20, angle=45, col="black")

points(Scale, RepCompetentMeans, type="l")

abline(0, 0, col="black", lty=2, lwd=2)

legend("bottomright", cex=.98, legend=c('Democrats', 'Republicans'), fill=c("gray72", "black"), density=c(NA, 30), angle=c(NA, 45), border=c(NA, "black"))

dev.off()


#############
#Feeling Thermometer

library(foreign)
library(lattice)
library(extrafont)
library(readstata13)
library(scales)
#library(sm)
loadfonts()
datadem<-read.dta13("MarginalMatrix_Dem_95ci_DYDX.dta")
datarep<-read.dta13("MarginalMatrix_Rep_95ci_DYDX.dta")
datademmean<-read.dta13("MarginalMatrix_Dem_Means_DYDX.dta")
datarepmean<-read.dta13("MarginalMatrix_Rep_Means_DYDX.dta")

Scale<-datadem[,1]
DemLeaderLB<-datadem[,2]
DemLeaderUB<-datadem[,3]
DemCompetentLB<-datadem[,4]
DemCompetentUB<-datadem[,5]
DemFTLB<-datadem[,6]
DemFTUB<-datadem[,7]
DemJobLB<-datadem[,8]
DemJobUB<-datadem[,9]
DemRightLB<-datadem[,10]
DemRightUB<-datadem[,11]
DemEffectiveLB<-datadem[,12]
DemEffectiveUB<-datadem[,13]

RepLeaderLB<-datarep[,2]
RepLeaderUB<-datarep[,3]
RepCompetentLB<-datarep[,4]
RepCompetentUB<-datarep[,5]
RepFTLB<-datarep[,6]
RepFTUB<-datarep[,7]
RepJobLB<-datarep[,8]
RepJobUB<-datarep[,9]
RepRightLB<-datarep[,10]
RepRightUB<-datarep[,11]
RepEffectiveLB<-datarep[,12]
RepEffectiveUB<-datarep[,13]

DemLeaderMeans<-datademmean[,2]
DemCompetentMeans<-datademmean[,3]
DemFTMeans<-datademmean[,4]
DemJobMeans<-datademmean[,5]
DemRightMeans<-datademmean[,6]
DemEffectiveMeans<-datademmean[,7]

RepLeaderMeans<-datarepmean[,2]
RepCompetentMeans<-datarepmean[,3]
RepFTMeans<-datarepmean[,4]
RepJobMeans<-datarepmean[,5]
RepRightMeans<-datarepmean[,6]
RepEffectiveMeans<-datarepmean[,7]

pdf(file="Figure2c.pdf", family="Bookman")
plot(0, 1, type="n", xlim=c(0,1), ylim=c(-.15, .15), xlab="Moderator: Perceived Obstructiveness", ylab="Marginal Effect of Gender on Feeling Thermoter Score")
title(main="Feeling Thermometer Score")
box() 

polygon(c(Scale, rev(Scale)), c(DemFTLB, rev(DemFTUB)), col="gray72", border=NA)

points(Scale, DemFTMeans, type="l")

polygon(c(Scale, rev(Scale)), c(RepFTLB, rev(RepFTUB)), density=20, angle=45, col="black")

points(Scale, RepFTMeans, type="l")

abline(0, 0, col="black", lty=2, lwd=2)

legend("bottomright", cex=.98, legend=c('Democrats', 'Republicans'), fill=c("gray72", "black"), density=c(NA, 30), angle=c(NA, 45), border=c(NA, "black"))

dev.off()


#############
#Job

library(foreign)
library(lattice)
library(extrafont)
library(readstata13)
library(scales)
#library(sm)
loadfonts()
datadem<-read.dta13("MarginalMatrix_Dem_95ci_DYDX.dta")
datarep<-read.dta13("MarginalMatrix_Rep_95ci_DYDX.dta")
datademmean<-read.dta13("MarginalMatrix_Dem_Means_DYDX.dta")
datarepmean<-read.dta13("MarginalMatrix_Rep_Means_DYDX.dta")

Scale<-datadem[,1]
DemLeaderLB<-datadem[,2]
DemLeaderUB<-datadem[,3]
DemCompetentLB<-datadem[,4]
DemCompetentUB<-datadem[,5]
DemFTLB<-datadem[,6]
DemFTUB<-datadem[,7]
DemJobLB<-datadem[,8]
DemJobUB<-datadem[,9]
DemRightLB<-datadem[,10]
DemRightUB<-datadem[,11]
DemEffectiveLB<-datadem[,12]
DemEffectiveUB<-datadem[,13]

RepLeaderLB<-datarep[,2]
RepLeaderUB<-datarep[,3]
RepCompetentLB<-datarep[,4]
RepCompetentUB<-datarep[,5]
RepFTLB<-datarep[,6]
RepFTUB<-datarep[,7]
RepJobLB<-datarep[,8]
RepJobUB<-datarep[,9]
RepRightLB<-datarep[,10]
RepRightUB<-datarep[,11]
RepEffectiveLB<-datarep[,12]
RepEffectiveUB<-datarep[,13]

DemLeaderMeans<-datademmean[,2]
DemCompetentMeans<-datademmean[,3]
DemFTMeans<-datademmean[,4]
DemJobMeans<-datademmean[,5]
DemRightMeans<-datademmean[,6]
DemEffectiveMeans<-datademmean[,7]

RepLeaderMeans<-datarepmean[,2]
RepCompetentMeans<-datarepmean[,3]
RepFTMeans<-datarepmean[,4]
RepJobMeans<-datarepmean[,5]
RepRightMeans<-datarepmean[,6]
RepEffectiveMeans<-datarepmean[,7]

pdf(file="Figure2d.pdf", family="Bookman")
plot(0, 1, type="n", xlim=c(0,1), ylim=c(-.15, .15), xlab="Moderator: Perceived Obstructiveness", ylab="Marginal Effect of Gender on Job Approval")
title(main="Job Approval")
box() 

polygon(c(Scale, rev(Scale)), c(DemJobLB, rev(DemJobUB)), col="gray72", border=NA)

points(Scale, DemJobMeans, type="l")

polygon(c(Scale, rev(Scale)), c(RepJobLB, rev(RepJobUB)), density=20, angle=45, col="black")

points(Scale, RepJobMeans, type="l")

abline(0, 0, col="black", lty=2, lwd=2)

legend("bottomright", cex=.98, legend=c('Democrats', 'Republicans'), fill=c("gray72", "black"), density=c(NA, 30), angle=c(NA, 45), border=c(NA, "black"))

dev.off()


#############
#Right

library(foreign)
library(lattice)
library(extrafont)
library(readstata13)
library(scales)
#library(sm)
loadfonts()
datadem<-read.dta13("MarginalMatrix_Dem_95ci_DYDX.dta")
datarep<-read.dta13("MarginalMatrix_Rep_95ci_DYDX.dta")
datademmean<-read.dta13("MarginalMatrix_Dem_Means_DYDX.dta")
datarepmean<-read.dta13("MarginalMatrix_Rep_Means_DYDX.dta")

Scale<-datadem[,1]
DemLeaderLB<-datadem[,2]
DemLeaderUB<-datadem[,3]
DemCompetentLB<-datadem[,4]
DemCompetentUB<-datadem[,5]
DemFTLB<-datadem[,6]
DemFTUB<-datadem[,7]
DemJobLB<-datadem[,8]
DemJobUB<-datadem[,9]
DemRightLB<-datadem[,10]
DemRightUB<-datadem[,11]
DemEffectiveLB<-datadem[,12]
DemEffectiveUB<-datadem[,13]

RepLeaderLB<-datarep[,2]
RepLeaderUB<-datarep[,3]
RepCompetentLB<-datarep[,4]
RepCompetentUB<-datarep[,5]
RepFTLB<-datarep[,6]
RepFTUB<-datarep[,7]
RepJobLB<-datarep[,8]
RepJobUB<-datarep[,9]
RepRightLB<-datarep[,10]
RepRightUB<-datarep[,11]
RepEffectiveLB<-datarep[,12]
RepEffectiveUB<-datarep[,13]

DemLeaderMeans<-datademmean[,2]
DemCompetentMeans<-datademmean[,3]
DemFTMeans<-datademmean[,4]
DemJobMeans<-datademmean[,5]
DemRightMeans<-datademmean[,6]
DemEffectiveMeans<-datademmean[,7]

RepLeaderMeans<-datarepmean[,2]
RepCompetentMeans<-datarepmean[,3]
RepFTMeans<-datarepmean[,4]
RepJobMeans<-datarepmean[,5]
RepRightMeans<-datarepmean[,6]
RepEffectiveMeans<-datarepmean[,7]

pdf(file="Figure2e.pdf", family="Bookman")
plot(0, 1, type="n", xlim=c(0,1), ylim=c(-.15, .15), xlab="Moderator: Perceived Obstructiveness", ylab="Marginal Effect of Gender on Rightness of Behavior")
title(main="Rightness of Behavior")
box() 

polygon(c(Scale, rev(Scale)), c(DemRightLB, rev(DemRightUB)), col="gray72", border=NA)

points(Scale, DemRightMeans, type="l")

polygon(c(Scale, rev(Scale)), c(RepRightLB, rev(RepRightUB)), density=20, angle=45, col="black")

points(Scale, RepRightMeans, type="l")

abline(0, 0, col="black", lty=2, lwd=2)

legend("bottomright", cex=.98, legend=c('Democrats', 'Republicans'), fill=c("gray72", "black"), density=c(NA, 30), angle=c(NA, 45), border=c(NA, "black"))

dev.off()


#############
#Effectiveness

library(foreign)
library(lattice)
library(extrafont)
library(readstata13)
library(scales)
#library(sm)
loadfonts()
datadem<-read.dta13("MarginalMatrix_Dem_95ci_DYDX.dta")
datarep<-read.dta13("MarginalMatrix_Rep_95ci_DYDX.dta")
datademmean<-read.dta13("MarginalMatrix_Dem_Means_DYDX.dta")
datarepmean<-read.dta13("MarginalMatrix_Rep_Means_DYDX.dta")

Scale<-datadem[,1]
DemLeaderLB<-datadem[,2]
DemLeaderUB<-datadem[,3]
DemCompetentLB<-datadem[,4]
DemCompetentUB<-datadem[,5]
DemFTLB<-datadem[,6]
DemFTUB<-datadem[,7]
DemJobLB<-datadem[,8]
DemJobUB<-datadem[,9]
DemRightLB<-datadem[,10]
DemRightUB<-datadem[,11]
DemEffectiveLB<-datadem[,12]
DemEffectiveUB<-datadem[,13]

RepLeaderLB<-datarep[,2]
RepLeaderUB<-datarep[,3]
RepCompetentLB<-datarep[,4]
RepCompetentUB<-datarep[,5]
RepFTLB<-datarep[,6]
RepFTUB<-datarep[,7]
RepJobLB<-datarep[,8]
RepJobUB<-datarep[,9]
RepRightLB<-datarep[,10]
RepRightUB<-datarep[,11]
RepEffectiveLB<-datarep[,12]
RepEffectiveUB<-datarep[,13]

DemLeaderMeans<-datademmean[,2]
DemCompetentMeans<-datademmean[,3]
DemFTMeans<-datademmean[,4]
DemJobMeans<-datademmean[,5]
DemRightMeans<-datademmean[,6]
DemEffectiveMeans<-datademmean[,7]

RepLeaderMeans<-datarepmean[,2]
RepCompetentMeans<-datarepmean[,3]
RepFTMeans<-datarepmean[,4]
RepJobMeans<-datarepmean[,5]
RepRightMeans<-datarepmean[,6]
RepEffectiveMeans<-datarepmean[,7]

pdf(file="Figure2f.pdf", family="Bookman")
plot(0, 1, type="n", xlim=c(0,1), ylim=c(-.15, .15), xlab="Moderator: Perceived Obstructiveness", ylab="Marginal Effect of Gender on Perceived Effectiveness")
title(main="Perceived Effectiveness")
box() 

polygon(c(Scale, rev(Scale)), c(DemEffectiveLB, rev(DemEffectiveUB)), col="gray72", border=NA)

points(Scale, DemEffectiveMeans, type="l")

polygon(c(Scale, rev(Scale)), c(RepEffectiveLB, rev(RepEffectiveUB)), density=20, angle=45, col="black")

points(Scale, RepEffectiveMeans, type="l")

abline(0, 0, col="black", lty=2, lwd=2)

legend("bottomright", cex=.98, legend=c('Democrats', 'Republicans'), fill=c("gray72", "black"), density=c(NA, 30), angle=c(NA, 45), border=c(NA, "black"))

dev.off()

